﻿using GameView.Comment;

namespace GameView.Models
{
    public class ApiResponse<T>
    {
        public bool Succeeded { get; set; } = false;
        public int StatusCode { get; set; } = 0;
        public T Data { get; set; }
        public object Errors { get; set; }
        public string Extras { get; set; } = "";
        public long Timestamp { get; set; } = 0;
        public ApiResponse()
        {
        }
        public ApiResponse(ApiResponse<string> response)
        {
            this.StatusCode = response.StatusCode;
            this.Errors = response.Data;
            this.Succeeded = response.Succeeded;
            this.Extras = response.Extras;
            this.Data = JSON.Deserialize<T>(response.Data);
        }
        public ApiResponse(ApiResponse<object> response)
        {
            this.StatusCode = response.StatusCode;
            this.Errors = response.Errors;
            this.Succeeded = response.Succeeded;
            this.Extras = response.Extras;
            if (response.Data != null)
                this.Data = JSON.Deserialize<T>(response.Data?.ToString());
            if (Data == null)
                Data = (T)response.Data;
        }
    }
}